<!-- 菜单悬浮的原理: 通过给菜单添加position:sticky实现, 用法超简单, 仅APP端的低端机不兼容 https://caniuse.com/#feat=css-sticky -->
<template>
	<view>
		<!-- 对于mescroll-body: 需设置:sticky="true", 此应避免在mescroll-body标签前面加其他非定位的元素, 否则下拉区域会被挤出, 无法会隐藏.-->
		<!-- 对于mescroll-uni: 则无需设置:sticky="true", 无其他限制和要求 -->
		<!-- sticky吸顶悬浮的菜单, 父元素必须是 mescroll -->
		<view class="sticky-tabs">
			<!-- <me-tabs v-model="tabIndex" nameKey='title' :tabs="tabs" @change="tabChange"></me-tabs> -->
			<view class="padding-tb-sm bg flex align-center">
				<view class="tui-tabs" style="width: 100%;">
					<scroll-view id="tab-bar" scroll-with-animation class="tui-scroll-h" :scroll-x="true"
						:show-scrollbar="false">
						<view style="display: flex;width: 100%;white-space: nowrap;overflow-x: auto;">
							<view :key='index' v-for="(item, index) in tabs"
								style="width:30%;margin-left: 16upx;text-align: center" :id="item.id"
								:data-current="index" @tap="tabChange(item)">
								<view class="nameclore" :class="{ 'tui-tab-item-title-active': tabIndex == item.id }">
									{{ item.title }}
								</view>
								<view class="weix" v-if="tabIndex == item.id">
									<image src="../../static/images/index/indexbottom.png"></image>
								</view>
							</view>
						</view>
					</scroll-view>
				</view>
			</view>
		</view>


		<!-- 数据列表 -->
		<view v-for="(item,index) in goods" :key='index' @click.stop="bindtakeDetail(item.helpOrderId)">
			<view class="bg margin-lr radius margin-top-sm">
				<view class="flex justify-between padding-lr padding-top-sm">
					<view>报价时间：{{item.offerTime}} </view>
					<view style="color: #557EFD;" v-if="item.status ==1">已雇佣</view>
					<view style="color: #557EFD;" v-if="item.status ==0">等待雇佣</view>
					<view style="color: #557EFD;" v-if="item.status ==2">雇佣失败</view>
				</view>
				<view style="border-top: 1rpx solid #F2F2F2;margin-top: 20upx;"></view>
				<view class="flex padding-lr padding-tb-sm">
					<image :src="item.img" style="width: 149upx;height: 149upx;"></image>
					<view class="margin-left-xs">
						<view class="flex justify-between text-lg text-bold  " style="width:480upx;">
							<view>{{item.classify_name}}</view>
							<view style="color: #557EFD;" v-if="item.task_type==2">报价任务<text
									class="text-sm">￥</text>{{item.offerMoney}}</view>
						</view>
						<view class=" text-26 margin-tb-xs text-cut" style="color: #999999;width: 480rpx;">
							服务地址：{{item.detailsAddress}}</view>
						<view class="flex text-26 " style="color: #999999;">预约时间：{{item.deliveryTime}}</view>
					</view>
				</view>
				<view class="flex align-end justify-end padding-lr padding-bottom" v-if="item.status ==1">
					<view class="btn" @click.stop="gojiedan">我的接单</view>
				</view>
			</view>
		</view>
		<empty v-if="goods.length == 0"></empty>


		<u-popup v-model="show" mode="center" width="500rpx" height="190px" border-radius="14" :closeable="true">
			<view class="padding-lr" style="margin-top: 30upx;">
				<view class="text-lg text-bold margin-bottom">确认码</view>
				<view class=" padding-lr-sm" style="background: #F5F5F5;">
					<!-- <input type="number" v-memo="codes" placeholder="请输入确认码" @confirm="change()"/> -->
					<u-input v-model="codes" type="number" placeholder="请输入确认码" @confirm="change()" />
				</view>
				<view class="btn3" @click="sure()">确认</view>
			</view>
		</u-popup>


	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import mescrollBody from "@/components/mescroll-uni/components/mescroll-body/mescroll-body.vue";
	import meTabs from "@/components/mescroll-uni/me-tabs/me-tabs.vue";
	import empty from '../../components/empty.vue'

	export default {
		mixins: [MescrollMixin], // 使用mixin
		components: {
			mescrollBody,
			meTabs,
			empty
		},
		data() {
			return {
				startTime: '',
				params: {
					year: true,
					month: true,
					day: true,
					hour: false,
					minute: false,
					second: false
				},
				showtime: false,
				orderNumber: '',
				phone: '',
				userName: '',
				SXshow: false,
				show: false,
				codes: '',
				goods: [], // 数据列表
				tabs: [{
					id: 0,
					title: '全部',
					status: ''
				}, {
					id: 1,
					title: '待雇佣',
					status: '0'
				}, {
					id: 2,
					title: '已雇佣',
					status: '1'
				}, {
					id: 3,
					title: '雇佣失败',
					status: '2'
				}],
				tabIndex: 0, // tab下标
				game: [],
				page: 1,
				limit: 10,
				userId: 0,
				status: 1,
				nickName: '',
				avatar: '',
				customStyle: {
					color: '#999999',
					border: '2rpx solid #999999',
					// backgroundColor: '#1E1F31',
					border: "8rpx",
					width: '180rpx',
					height: '54rpx',
					margin: "0 0 0 20rpx"
				},
				customStyle1: {
					color: '#557EFD',
					border: '2rpx solid #557EFD',
					// backgroundColor: '#1E1F31',
					border: "8rpx",
					width: '180rpx',
					height: '54rpx',
					margin: "0 0 0 20rpx"
				},
				helpTakeId: '',
				helpOrderId: ''
			}
		},
		onLoad() {
			this.$queue.showLoading("加载中...");
			this.userId = uni.getStorageSync('userId')
			this.nickName = uni.getStorageSync('nickName')

		},
		onShow() {
			this.orderlist()
		},
		methods: {
			gojiedan(){
				uni.redirectTo({
					url:'/my/takeOrder/index'
				})
			},
			// 接单详情
			bindtakeDetail(id) {
				console.log('8888888', id)
				uni.navigateTo({
					// url: './takeDetail?id=' + id
					url: '/my/takeOrder/baojiaDet?id=' + id
				})
			},
			openShaixuan() {
				this.SXshow = !this.SXshow
			},
			confirm(e) {
				this.startTime = e.year + '-' + e.month + ' ' + e.day
				// console.log(e,this.startTime )
			},
			bindx() {
				this.SXshow = false
				this.orderlist()
				this.phone = ''
				this.userName = ''
				this.orderNumber = ''
			},
			orderlist() {
				let curTab = this.tabs[this.tabIndex].status

				let data = {
					status: curTab,
					page: this.page,
					limit: this.limit,
					// taskType:2
				}
				this.$Request.get('/app/help/getMyOfferOrder', data).then(res => {
					if (res.code == 0) {
						for (let i = 0; i < res.data.records.length; i++) {
							if (res.data.records[i].gameName) {
								res.data.records[i].gameName = res.data.records[i].gameName.split(",");
							}
						}
						if (this.page == 1) {
							this.goods = res.data.records //如果是第一页需手动制空列表
						} else {
							this.goods = [...this.goods, ...res.data.records]; //追加新数据
						}



					}
					uni.hideLoading();
					uni.stopPullDownRefresh()

				})
			},
			// 切换菜单
			tabChange(tab) {
				this.tabIndex = tab.id
				this.goods = []; // 置空列表,显示加载进度条
				this.page = 1
				this.orderlist()
			},
			// 输入验证码
			openCode(e) {
				this.show = true
				this.helpTakeId = e.helpTakeId
				this.helpOrderId = e.helpOrderId
			},
			change(e) {
				this.codes = e
			},
			sure() {
				console.log(this.codes, '000000')
				let data = {
					helpTakeId: this.helpTakeId,
					helpOrderId: this.helpOrderId,
					code: this.codes
				}
				this.$Request.post('/app/help/closeOrder', data).then(res => {
					if (res.code == 0) {
						this.show = false
						this.codes = ''
						this.orderlist()
					} else {
						this.show = false
						this.codes = ''
						uni.showToast({
							title: '确认码不正确！',
							icon: 'none',
							duration: 1000
						})
					}
				})
			},
			// 取消订单
			cancelOrder(e) {
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定取消订单吗？',
					success: function(res) {
						if (res.confirm) {
							let data = {
								id: e.helpTakeId
							}
							that.$Request.post('/app/help/endHelpTake', data).then(res => {
								if (res.code == 0) {
									that.orderlist()
								}
							})
						}
					},
				})
			},
			clickItem: function(options) {
				let data = {
					userId: this.userId,
					focusedUserId: options.ordersUserId,
					userType: 2
				}
				this.$Request.postJson('/app/chat/insertChatConversation', data).then(res => {
					if (res.code == 0) {
						let id = this.userId == res.data.userId ? res.data.focusedUserId : this.userId
						uni.navigateTo({
							url: '/pages/msg/im?chatConversationId=' + res.data.chatConversationId +
								'&byUserId=' + id
						})
					}
				})
			}
		},
		onReachBottom: function() {
			this.page = this.page + 1;
			this.orderlist()
		},
		onPullDownRefresh: function() {
			this.page = 1;
			this.orderlist()
		},
	}
</script>

<style lang="scss">
	/*
	sticky生效条件：
	1、父元素不能overflow:hidden或者overflow:auto属性。(mescroll-body设置:sticky="true"即可, mescroll-uni本身没有设置overflow)
	2、必须指定top、bottom、left、right4个值之一，否则只会处于相对定位
	3、父元素的高度不能低于sticky元素的高度
	4、sticky元素仅在其父元素内生效,所以父元素必须是 mescroll
	*/
	.sticky-tabs {
		z-index: 990;
		position: sticky;
		top: var(--window-top);
		// background-color: #fff;
	}

	// 使用mescroll-uni,则top为0
	.mescroll-uni,
	/deep/.mescroll-uni {
		.sticky-tabs {
			top: 0;
		}
	}

	.demo-tip {
		padding: 18upx;
		font-size: 24upx;
		text-align: center;
	}

	page {
		background-color: #F7F7F7;
	}

	.bg {
		background-color: #FFFFFF;
	}

	.tabber {
		width: 100%;
		background: #ffffff;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		justify-content: flex-end;
		height: 127rpx;
	}

	.weix image {
		width: 54upx;
		height: 15upx;
	}

	.nameclore {
		text-align: center;
		font-size: 28upx;
		padding: 0rpx 20rpx;
	}

	.nameclore.tui-tab-item-title-active {
		color: #5E81F9;
		font-size: 30upx;
	}

	.btn3 {
		background: #557EFD;
		border-radius: 16upx;
		text-align: center;
		color: #FFFFFF;
		padding: 20rpx 10rpx;
		margin-top: 60rpx;
	}

	.btn1 {
		background: #F5F5F5;
		color: #999999;
		padding: 10upx 25upx;
		border-radius: 40upx;
		margin-right: 20upx;
		// border: 1upx solid #666666;
	}

	.btn2 {
		background: #5E81F9;
		color: #FFFFFF;
		padding: 10upx 25upx;
		border-radius: 40upx;
	}
	.btn{
		background: #557EFD;
		border-radius: 16upx;
		text-align: center;
		color: #FFFFFF;
		padding: 10upx 25upx;
		
	}
</style>